package thread;

public class Demo8 {
    public static void main(String[] args) throws InterruptedException {

        Thread t = new Thread(()->{
            //Thread.currentThread()类似于this，表示获取当前线程信息
            while(!Thread.currentThread().isInterrupted()){

                System.out.println(Thread.currentThread().getName());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //该线程掀桌
                    //e.printStackTrace();
                    break;
                }
            }
            System.out.println("thread 线程结束");
        }, "thread");

        t.start();
        //主动修改线程的终止状态
        Thread.sleep(3000);
        System.out.println(" main 线程尝试终止 thread 线程");

        //设置标志位，唤醒sleep等阻塞方法
        t.interrupt();

    }
}
